package smallchange;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
import java.util.logging.SimpleFormatter;

public class SmallChangeSys {
    public static void main(String[] args) {
        Scanner myscanner = new Scanner(System.in);
        String key = "";
//        2.零钱通明细
       // (1)可以把收益入账和消费，保存到数组(2)可以使用对象(3)简单的话可以使用string拼接
        String details="----------零钱通明细-------------";

//        3.收益入账
        double money = 0;
        double balance = 0;
        Date date = null;
        SimpleDateFormat sdf =new SimpleDateFormat( "yyyy-MM-dd HH:mm");//用于日期格式化


//      4.消费
        String note ="";//消费说明
        boolean loop =true;
        do {
            System.out.println("\n==========零钱通菜单===========");
            System.out.println("\t\t\t1 零钱通明细");
            System.out.println("\t\t\t2 收益入账");
            System.out.println("\t\t\t3 消费");
            System.out.println("\t\t\t4 退     出");

            System.out.println("请选择1-4");
            key = myscanner.next();
//使用switch分支控制
            switch (key){
                case "1":
                    System.out.println(details);
                    break;
                case "2":
                    System.out.println(" 收益入账金额");
                    money = myscanner.nextDouble();
                    //找出不正确的金额
                    if(money<=0){
                        System.out.println("收益入账金额 需要 大于 0");
                    break;
                    }
                    //找出正确的金额
                    balance += money;
                    date = new Date();//获取当前的日期
                    details +="\n收益入账\t" + money +"\t"+sdf.format(date)+"\t"+balance ;
                    break;
                case  "3":
                    System.out.println("消费金额");
                    money = myscanner.nextDouble();
                    if (money<=0||money > balance){
                        System.out.println("消费金额应该在0-"+balance);
                    break;
                    }
                    System.out.println("请输入消费说明");
                    note = myscanner.next();
                    balance -=money;
                    details +="\n" + note +"\t-"+money+"\t"+sdf.format(date)+"\t"+balance ;
                    break;
                case "4":
//                    System.out.println("4 退出");

                    String choice ="";
                    while (true){
                        System.out.println("你确定要退出吗？y/n");
                        choice = myscanner.next();
                        if ("y".equals(choice)||"n".equals(choice)){
                            break;
                        }
                    }
                    if (choice.equals("y")) {
                        loop = false;
                    }
                    break;
                default:
                    System.out.println("选择有误，请重新选择");
            }


        }while (loop);
        System.out.println("退出了零钱通项目");
    }
}
